﻿using System.Collections.Generic;
using System.Linq;
using RTM.API.Data;

namespace Hoguet.RTM
{
    public class RtmTaskFacadeConverter : IRtmTaskFacadeConverter
    {
        private readonly IRtmTimeEstimator _timeEstimator;

        public RtmTaskFacadeConverter(IRtmTimeEstimator timeEstimator)
        {
            _timeEstimator = timeEstimator;
        }
        public IEnumerable<RtmTaskFacade> Convert(IEnumerable<RtmTaskSeries> tasks)
        {
            return tasks.Select(taskSeries => new RtmTaskFacade(){
                Name = taskSeries.Name
                ,HoursRemaining = _timeEstimator.GetEstimateInHours(taskSeries.Task.Estimate)
                ,Due = taskSeries.Task.Due
                ,Repeat = taskSeries.RRule
                ,DateCreated = taskSeries.Task.Added.Value
            });
        }
    }
}